package core.genetic.crossover;

import java.util.Random;

import utility.Utils;

import core.genetic.Individual;

public class DoublePointCrossover implements Crossover{

	@Override
	public Individual crossover(Individual ind1, Individual ind2) {
		int length = ind1.getLength();
		Individual ind = new Individual(length);
		int point1 = Utils.random.nextInt(length);
		int point2 = point1 + Utils.random.nextInt(length-point1);
		for (int i=0; i<point1; i++){
			ind.setGene(i, ind1.getGene(i));
		}
		for (int i=point1; i<point2; i++){
			ind.setGene(i, ind2.getGene(i));
		}
		for (int i=point2; i<length; i++){
			ind.setGene(i, ind1.getGene(i));
		}
		return ind;
	}

}
